/******************************************************************************
//             INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//    Copyright(c) 2000 - 2001 Intel Corporation. All Rights Reserved.
//
//  VSS: 
//     $Workfile: $
//     $Revision: $
//     $Date:     $
//     $Archive:  $
//
//  Description:
//      Intel(R) Integrated Performance Primitives - JPEG Helper file.
//      This file contains level shift functions for encoding. 
//
//  History:
//     Date         Author        Changes
//     2000/5/10    Jerry Hu      Created  (Version 0.1)
//     2001/2/12    Jerry Hu      Modified (Version 0.2)
//
********************************************************************************/
#include "_ippjpeg.h"

/*
#define _SHIFTLEVEL_16U16S(x, level) ((Ipp16s)((int)(x)-level))
IPPFUN(IppStatus, ippiShiftLevelFwd_8u16s_C1R) (const Ipp8u *pSrc,
                                                int srcStep,
                                                Ipp16s *pDstMCU,
                                                const IppiRect *pRect)
{
    int x, y;
    int nOffset;
    int nWidth, nHeight;
    int nRowCount, nColCount;
    IppiSize size;
    const Ipp8u *pPtr, *pMCUPtr; 

    nWidth = pRect->right  - pRect->left;
    nHeight= pRect->bottom - pRect->top;

    _IPP_CHECK_ARG((0<nWidth)&&(0<nHeight));

    nOffset=pRect->top*srcStep+pRect->left;
    pPtr=pSrc+nOffset;
    nOffset=8*srcStep;
    nColCount=nWidth>>3;
    nRowCount=nHeight>>3; 
    nWidth&=7;
    nHeight&=7;

    pMCUPtr=pPtr;

    for (y=nRowCount; y>0; y--) {

        for (x=nColCount; x>0; x--) {
            ippiShiftLevelFwd_8x8_8u16s_C1 (pMCUPtr,
                                            srcStep,
                                            pDstMCU);
            pMCUPtr+=8;
            pDstMCU+=8; 
        }

        if (0<nWidth) {
            size.width=nWidth;
            size.height=8;
            ippiShiftLevelFwd_8x8_8u16s_C1R(pMCUPtr,
                                            srcStep,
                                            pDstMCU,
                                            size);
            pMCUPtr+=8;
            pDstMCU+=8; 
        }

        pPtr+=nOffset;
        pMCUPtr=pPtr;
    }

    if (0<nHeight) {
        size.width=8;
        size.height=nHeight;
        for (x=nColCount; x>0; x--) {
            ippiShiftLevelFwd_8x8_8u16s_C1R(pMCUPtr,
                                            srcStep,
                                            pDstMCU,
                                            size);
            pMCUPtr+=8;
            pDstMCU+=8; 
       }

       if (0<nWidth) {
           size.width=nWidth;
           ippiShiftLevelFwd_8x8_8u16s_C1R(pMCUPtr,
                                            srcStep,
                                            pDstMCU,
                                            size);
        }
    }

    return IPP_STATUS_OK;
}
*/

/******************************************************************************
// Name:             ippiLevelShiftSub128_8x8_8u16s_C1
// Description:      Convert each input sample from an unsigned representation to
//                   a two's complement representation.
// Input Arguments:
//             pSrc: Identifies image data buffer.    
//          srcStep: Specifies the number of bytes in a line within 
//                   the image data buffer.  
// Output Arguments:
//          pDst:    Identifies a output MCU buffer.
//                          
// Remarks:      
//                   1. The start address of "pDst" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignment at 32byte boundary to optimize 
//                      D-Cache accessing.
//
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiLevelShiftSub128_8x8_8u16s_C1) (const Ipp8u *pSrc,
                                                      int srcStep,
                                                      Ipp16s *pDst)
{
    int i;

    _IPP_CHECK_ARG(NULL!=pSrc && NULL!=pDst);
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrc));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pDst));
    _IPP_CHECK_ARG(0!=srcStep);

    for (i=0; i<8; i++) {
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[0]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[1]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[2]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[3]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[4]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[5]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[6]);
        *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[7]);
        pSrc+=srcStep;
    } /* for (i=0; i<8; i++) */

    return IPP_STATUS_OK;
}

/******************************************************************************
// Name:             ippiLevelShiftSub128_8x8_8u16s_C1R
// Description:      Convert each input sample from an unsigned representation to
//                   a two's complement representation. It processes ROI in 8x8 block
// Input Arguments:
//             pSrc: Identifies image data buffer.    
//          srcStep: Specifies the number of bytes in a line within 
//                   the image data buffer.  
//          roiSize: Identifies rectangle size for ROI
//
// Output Arguments:
//             pDst: Identifies a MCU buffer.
//                          
// Remarks:      
//                   1. The start address of "pDst" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignment at 32byte boundary to optimize 
//                      D-Cache accessing.
//
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiLevelShiftSub128_8x8_8u16s_C1R) (const Ipp8u *pSrc,
                                                       int srcStep,
                                                       Ipp16s *pDst,
                                                       IppiSize roiSize)
{
    int i, j, width, height;
    Ipp16s data, *pDstPtr;

    _IPP_CHECK_ARG(NULL!=pSrc && NULL!=pDst);
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrc));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pDst));
    _IPP_CHECK_ARG(0!=srcStep);
    _IPP_CHECK_ARG((0<roiSize.width)&&(8>=roiSize.width));
    _IPP_CHECK_ARG((0<roiSize.height)&&(8>=roiSize.height));

    width=roiSize.width;
    height=roiSize.height;

    for (i=0; i<height; i++) {
        for (j=0; j<width; j++) {
            *pDst++=_IPP_SHIFTLEVEL_8U16S(pSrc[j]);
        }
        data=pDst[-1];
        for (; j<8; j++){
            *pDst++=data;
        }
        pSrc+=srcStep;
    } /* for (i=0; i<8; i++) */

    pDstPtr=pDst-8;
    for (; i<8; i++) {
        for (j=0; j<8; j++) {
            pDst[j]=pDstPtr[j];
        }
        pDst+=8;
    } 

    return IPP_STATUS_OK;
}

/* EOF */
